package net.siufung.market.base.user.controller.regulation;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import net.siufung.core.exception.BizServiceException;
import net.siufung.core.model.regulation.AbstractRegulation;
import net.siufung.market.base.user.enums.UserSupers;
import net.siufung.market.base.user.mapper.IUserMapper;
import net.siufung.market.base.user.mapper.entity.User;

/**
 * @author 陈建峰
 * @since 2022/4/18 2:09 下午
 */
@AllArgsConstructor
public class UserResetPasswdRegulation extends AbstractRegulation<Integer> {

    private static final long serialVersionUID = 4278919973675557941L;

    private final IUserMapper userMapper;

    @Override
    public boolean isSatisfiedBy(Integer userId) {
        User user = userMapper.selectById(userId);
        if(ObjectUtil.isNull(user)){
            throw new BizServiceException("当前用户不存在！");
        }
        if(UserSupers.IS.equals(UserSupers.get(user.getAdminState()))){
            throw new BizServiceException("管理员密码不能重置！");
        }
        return Boolean.TRUE;
    }
}
